/* 
 * @(#) ListProductName.java  1.0  2004-4-19 
 * 
 * Copyright 2003 by LongTop Corporation. 
 * All rights reserved. 
 * 
 * This software is the confidential and proprietary information of 
 * LongTop Corporation ("Confidential Information").  You 
 * shall not disclose such Confidential Information and shall use 
 * it only in accordance with the terms of the license agreement 
 * you entered into with LongTop. 
 */

package com.cnc.tag;

import com.cnc.bas.IBasService;
import com.cnc.bas.util.Constants;
import com.cnc.bas.util.StringUtil;
import com.cnc.ssm.model.PwOper;

import org.apache.struts.util.ResponseUtils;

import javax.servlet.jsp.JspException;
import java.util.Iterator;
import java.util.List;

/**
 * @author Dubf
 * @version 1.0
 */
public class ListAllOperTag extends LtcmTag {
    protected boolean disabled = false;
    private boolean condition = false;
    private boolean showcode = false;

    public ListAllOperTag() {
        super();
    }

    public boolean isCondition() {
        return condition;
    }

    public void setCondition(boolean condition) {
        this.condition = condition;
    }

    public boolean isDisabled() {
        return disabled;
    }

    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

    public boolean isShowcode() {
        return showcode;
    }

    public void setShowcode(boolean showcode) {
        this.showcode = showcode;
    }

    public int doEndTag() throws JspException {
        IBasService basService = (IBasService) this.getBean(Constants.BEAN_NAME_BAS);
        List list = basService.listAll(PwOper.class, "operCode");
        Iterator iter = list.iterator();
        StringBuffer results = new StringBuffer();
        if (condition) {
            results.append("<option value=''");
            if (disabled) {
                results.append(" disabled=\"disabled\"");
            }
            results.append(">");

            results.append("</option>");
        }
        while (iter.hasNext()) {
            PwOper obj = (PwOper) iter.next();
            results.append("<option value=\"");
            results.append(obj.getOperCode().trim());
            results.append("\" ");
            if (disabled) {
                results.append(" disabled=\"disabled\"");
            }
            results.append(">");
            if (this.showcode)
                results.append(StringUtil.toFixLength(obj.getOperCode(), 20) + "  |  ");
            results.append(obj.getOperName() == null ? "" : obj.getOperName().trim());
            results.append("</option>");
        }
        ResponseUtils.write(pageContext, results.toString());
        return (EVAL_PAGE);
    }
}

